<%@ page import="java.util.List" %>
<%@ page import="com.huazi.www.doctor.hu.entity.Drug" %>
<%@ page import="com.huazi.www.doctor.hu.service.impl.DoctorServiceImpl" %>
<%@ page import="com.huazi.www.doctor.hu.entity.Medicine" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%--
  Created by IntelliJ IDEA.
  User: 29513
  Date: 2021/5/7
  Time: 9:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><%
    //获取项目的根路径
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
    <title>Title</title>
    <meta charset="utf-8">
    <title>Layui</title>
    <link rel="stylesheet" href="<%=basePath%>swee/sweetalert.css">
    <script src="<%=basePath%>swee/sweetalert-dev.js"></script>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css" media="all">
    <script src="<%=basePath%>layui-v2.6.5/layui/layui.js" type="text/javascript"></script>

    <script src="<%=basePath%>doctor/js/jquery-1.12.4.js" type="text/javascript" ></script>
    <script src="<%=basePath%>doctor/js/check.js" type="text/javascript" ></script>
    <link rel="stylesheet" href="<%=basePath%>doctor/css/check.css" media="all">
    <%--    <script src="<%=basePath%>layui-v2.6.5/layui/layui.js"></script>--%>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css"  media="all">

</head>
<body>






<div style="height: 50px"></div>
<%--候诊队列--%>
<div class="checkqueue" >
    <div class="layui-form">
        <form action="<%=basePath%>queue" method="post">
            <input type="text" name="name" lay-verify="email" autocomplete="off" class="name" >
            <button type="submit" id="select" class="layui-btn layui-btn-radius" name="nameselect">查询</button>
            <%----%>
            <button type="submit" id="selectall" class="layui-btn layui-btn-radius" name="selectall" value="selectall">记录</button>
        </form>

        <table class="layui-table" lay-even="" lay-skin="row">
            <colgroup>
                <col width="150">
                <col width="150">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>序号</th>
                <th>诊断号</th>
                <th>名字</th>


                <th>操作</th>

            </tr>
            </thead>
            <tbody class="bangding">
            <c:forEach items="${requestScope.page.newsList}" var="list">
                <tr >
                    <td>${list.id}</td>
                    <td>${list.patientId}</td>
                    <td>${list.patientName}</td>


                    <c:if test="${state==null}">
                        <td> <button type="button" id="ok" class="layui-btn layui-btn-radius">确认问诊</button></td>
                    </c:if>
                    <c:if test="${state!=null}">
                        <td>
                            <c:if test="${state!=null}">
                                <c:if test="${list.state==0}">
                                    <button type="button" class="layui-btn layui-btn-radius">未确诊</button>
                                </c:if>
                                <c:if test="${list.state==1}">
                                    <button type="button" class="layui-btn layui-btn-warm layui-btn-radius">问诊中</button>
                                </c:if>
                                <c:if test="${list.state==2}">
                                    <button type="button" class="layui-btn layui-btn-danger layui-btn-radius">已确诊</button>
                                </c:if>

                            </c:if>
                        </td>
                    </c:if>


                </tr>
            </c:forEach>
            </tbody>
        </table>



        <span id="qiehuan" colspan="8" align="center">
                      <c:if test="${state==null}">
                          <c:if test="${requestScope.page.currPageNo>1}" >
                        <a href="<%=basePath%>queue?currentPage=${requestScope.page.currPageNo-1}&name=${name}">
                            <button class="layui-btn layui-btn-primary layui-border-green">上一页</button>
                        </a>
                          </c:if>
                          <c:if test="${requestScope.page.currPageNo<requestScope.page.totalPageCount}" >
                        <a href="<%=basePath%>queue?currentPage=${requestScope.page.currPageNo + 1}&name=${name}">
                            <button class="layui-btn layui-btn-primary layui-border-green">下一页</button>
                        </a>
                          </c:if>
                      </c:if>
            <c:if test="${state!=null}">
                <c:if test="${requestScope.page.currPageNo>1}" >
                        <a href="<%=basePath%>queue?currentPage=${requestScope.page.currPageNo-1}&name=${name}&selectall=selectall">
                            <button class="layui-btn layui-btn-primary layui-border-green">上一页</button>
                        </a>
                </c:if>
                <c:if test="${requestScope.page.currPageNo<requestScope.page.totalPageCount}" >
                        <a href="<%=basePath%>queue?currentPage=${requestScope.page.currPageNo + 1}&name=${name}&selectall=selectall">
                            <button class="layui-btn layui-btn-primary layui-border-green">下一页</button>
                        </a>
                </c:if>
            </c:if>
                </span>
    </div>
</div>

<%--检查队列--%>
<div class="checkduiwu">
    <div id="big">
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="150">
                <col width="150">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>病人编号</th>
                <th>病人姓名</th>

                <th>状态</th>

            </tr>
            </thead>
            <tbody id="tbody">
            <tr style="display: none">
                <td>1</td>
                <td>2</td>
                <td>3</td>
            </tr>
            <c:forEach items="${pat.list}" var="pat">
                <tr  >
                    <td>${pat.getPatientId()}</td>
                    <td>${pat.getPatientName()}</td>
                    <td>问诊中</td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>

<%--开具检查单--%>
<div class="checkdan">


        <h3 style="">检查单</h3>
        </span>

        <form class="layui-form" action="" style="background-color: white;">
            <div class="layui-inline">
                <label class="layui-form-label"   >诊断号:</label>
                <div class="layui-input-inline">
                    <input type="tel" name=""  autocomplete="off" class="layui-input" readonly>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">姓名:</label>
                <div class="layui-input-inline">
                    <input type="text" name=""  autocomplete="off" class="layui-input" readonly>
                </div>
            </div>
            <br><br>

            <label class="layui-form-label">检查项目</label>
            <div class="layui-input-inline">
                <select name="modules" lay-verify="required" lay-search="">
                    <option value="0">CT</option>
                    <option value="1">和磁共振</option>
                    <option value="2">B超</option>
                    <option value="3">心电图</option>
                    <option value="4">常规检查</option>
                </select>
            </div>
        </form>
        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="checkok">确认</button>




</div>

<%--个人详细信息--%>
<div class="info">




<%--    处方笺--%>
    <div class="chufanginfo">
        <p id="docid" style="display: none">${sessionScope.doctor.doctorId}</p>
        <p id="docname" style="display: none">${sessionScope.doctor.doctorName}</p>
        <div class="yaodann">
            <h1 style="color:#009f95;">华子医院</h1>
            <h3 style="color:#009f95;">门诊处方笺</h3>
            <br>
            <form action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">诊断号:</label>
                        <div class="layui-input-inline">
                            <input type="tel" name=""  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">姓名:</label>
                        <div class="layui-input-inline">
                            <input type="text" name=""  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">医生:</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="doctor"  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间:</label>
                        <div class="layui-input-inline">
                            <input type="text" id="myclock"  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">诊断结果:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="" id="bingli"  autocomplete="off" class="layui-input" style=" width:300px ;border: none;border-bottom: 1px solid #009f95;">
                        </div>
                    </div>
                </div>




                <div id="wz" style="background-color: white;" >
                    <div id="test7" class="demo-transfer" style="margin-left: 20px" class="wezhi"></div>
                    <div class="layui-btn-containesumr" style="margin-left: 20px" class="wezhi">
                        <button type="button" class="" lay-demotransferactive="getData" id="suoding"></button>
                        <button type="button" class="layui-btn" lay-demotransferactive="getData" id="n">√</button>
                        <button type="button" class="layui-btn" lay-demotransferactive="reload" id="sousuo">搜索药品</button>
                    </div>
                </div>

                <button type="button" class="layui-btn"  id="drugok">确认开药</button>
                <div class="drugshow"></div>
                <div class="sum">
                    <p class="drugdan" style="font-size: 15px">
                        药品号<span STYLE="margin-left: 80px;"></span>
                        药品名<span STYLE="margin-left: 90px;"></span>
                        数量<span STYLE="margin-left: 80px;"></span>
                        剂量</p>

                </div>
            </form>


        </div>
        </div>



<%--    右侧边盒子--%>
<div class="checktype">

    <div class="check-bingli">
        <p style="width: 50px; color: #0bc9be;font-size: 20px; margin: auto;">病史</p>
        <div class="binglich">
            <table class="layui-table" lay-skin="line">
                <tr>
                    <th>病例</th>
                    <th>患病时间</th>
                </tr>
            </table>
        </div>


    </div>

    <div class="check-ct">
        <p style="width: 100px; color: #0bc9be;font-size: 20px; margin: auto;">检查记录</p>
        <div class="ctch">
            <table class="layui-table" lay-skin="line">
                <tr>
                    <th>部位</th>
                    <th>结果</th>
                    <th>时间</th>
                </tr>
            </table>
        </div>
    </div>


<%--    /操作--%>
    <div class="cz">
        <a href="<%=basePath%>MedicineServlet?docid=<%=request.getAttribute("doctorid")%>&doctorname=<%=request.getAttribute("doctorname")%>"><button type="button" class="layui-btn" lay-demotransferactive="getData" id="drugrecord">药单</button></a>
        <a href="<%=basePath%>DoctorServlet"><button type="button" class="layui-btn">患者详情</button></a>
    </div>

<%--    主诉--%>
    <div class="zhusu">
        <p style="color: #0bc9be;font-size: 20px;width: 60px;margin: auto">主诉：</p>
        <textarea style="width: 300px;height: 77px;">

        </textarea>
    </div>



</div>





<script type="text/javascript">
    var arr=new Array()//id
    var arrname=new Array()//药名
    <%
     DoctorServiceImpl service=new DoctorServiceImpl();
     List<Drug> li=service.list();
    %>

    var getDataa=null
    layui.use(['transfer', 'layer', 'util'], function(){
        var $ = layui.$
            ,transfer = layui.transfer
            ,layer = layui.layer
            ,util = layui.util;


        //获得数据库所有药的数据

        var data1 = [
            <%
            for (int i=0;i<li.size();i++){
            %>
            {"value":'<%=li.get(i).getDrugid()%>' , "title": '<%=li.get(i).getDrugname()%>'},
            <%}%>
        ]
        //基础效果
        transfer.render({
            elem: '#test1'
            ,data: data1
        })
        //定义标题及数据源
        transfer.render({
            elem: '#test2'
            ,title: ['候选文人', '获奖文人']  //自定义标题
            ,data: data1
            //,width: 150 //定义宽度
            ,height: 210 //定义高度
        })
        //显示搜索框
        // transfer.render({
        //     elem: '#test4'
        //     ,data: data1
        //     ,title: ['文本墨客', '获奖文人']
        //     ,showSearch: true
        // })

        //数据格式解析
        transfer.render({
            elem: '#test5'
            ,parseData: function(res){
                return {
                    "value": res.id //数据值
                    ,"title": res.name //数据标题
                    ,"disabled": res.disabled  //是否禁用
                    ,"checked": res.checked //是否选中
                }
            }
            ,data: [
                {"id": "1", "name": "李白"}
                ,{"id": "2", "name": "杜甫"}
                ,{"id": "3", "name": "贤心"}
            ]
            ,height: 150
        })

        //穿梭时的回调
        // transfer.render({
        //     elem: '#test6'
        //     ,data: data1
        //     ,onchange: function(obj, index){
        //         var arr = ['左边', '右边'];
        //         layer.alert('来自 <strong>'+ arr[index] + '</strong> 的数据：'+ JSON.stringify(obj)); //获得被穿梭时的数据
        //     }
        // })

        //实例调用
        transfer.render({
            elem: '#test7'
            ,data: data1
            ,id: 'key123' //定义唯一索引
        })
        //批量办法定事件
        util.event('lay-demoTransferActive', {
            getData: function(othis){

                getDataa = transfer.getData('key123'); //获取右侧数据
                $(function (){

                    var count=0;
                    for(var i in getDataa) {

                        count++;
                    }

                    for(i=0;i<count;i++) {
                        $(".drugdan").after("<p class="+"xunhuan"+"><span>"+
                            getDataa[i].value+"</span><span>"+getDataa[i].title+"</span><input type='text' value='5' style='margin-left: 50px'>盒"+"" +
                            " <input type='text' id='yizhu' value='每日3片' style='margin-left: 70px;border: none;border-bottom: 1px solid #e3e2e2 '> <button style='margin-left: 10px' class='del-child'>×</button></p>")
                    }


                })
                // layer.alert(JSON.stringify(getDataa));
            }
            ,reload:function(){
                //实例重载
                transfer.reload('key123', {
                    title: ['药库', '开药']
                    ,value: []
                    ,showSearch: true
                })
            }
        });


    });
</script>
<script type="text/javascript">








    $("#ctDiv").hide();//隐藏CT结果
    $("#DisDiv").hide();//隐藏以往病例
    $("#open").hide();//隐藏开药盒子

    $(function (){
        $(".ct").click(function (){
            $(this).addClass("layui-btn layui-btn-disabled");
            $("#big").css({"opacity":"0.2","background-color":"#a9a9a9"});
        })
        $(".bl").click(function () {
            $(this).addClass("layui-btn layui-btn-disabled");
            $("#big").css({"opacity":"0.2"});
        })
        $("#CtClose").click(function () {
            $("#ctDiv").hide();
            $(".ct").removeClass("layui-btn-disabled");
            $("#ctDiv tbody").find("tr").remove();
            $("#big").css({"opacity":"1"});
        })
        $("#DisClose").click(function () {
            $("#DisDiv").hide();
            $(".bl").removeClass("layui-btn-disabled");
            $("#DisDiv tbody").find("tr").remove();
            $("#big").css({"opacity":"1"});
        })

        //开药
        // $("#kaiyao").click(function (){
        //     $(".yaodand").show()
        // })
        $("#tbody").on("click","#kaiyao",function (){
            $(".yaodand").show()
            $(".yaodan").show()
            $(".drugdan~p").remove();

            // 获得所有开药框所有的节点
            for (var i=0,j=1;i<4;i++,j++)
            {

                $(".layui-form-item input:eq("+i+")").val($(this).parent().parent().parent().children("td:eq("+j+")").text())
            }
            $(".layui-form-item input:eq(3)").val("")

        })
        // 确认开药
        $("#drugok").click(function (){
            //获取 诊断号
            var id= $(".layui-form-item input:eq(0)").val()
            //获取 姓名
            var name= $(".layui-form-item input:eq(1)").val()
            //获取 医生
            var doctorid= $("#docid").text()
            //获取 时间
            var time=$(".layui-form-item input:eq(3)").val()
            //得到药品长度
            var len=$(".drugdan~p").length;



            var drugid=new Array();
            var drugsum=new Array();
            var drugtype=new Array();
            //获取节点的药品 数量 医嘱等信息
            var arrlist=$(".drugdan~p")

            for (var i=0;i<len;i++)
            {
                drugid[i]=$(arrlist[i]).children("span:eq(0)").text()
                drugsum[i]=$(arrlist[i]).children("input:eq(0)").val()
                drugtype[i]=$(arrlist[i]).children("input:eq(1)").val()
            }
            let strid = drugid.join("-");
            let strsum=drugsum.join("-");
            let strtype=drugtype.join("-");

            if($("#bingli").val()==null || $("#bingli").val()=="")
            {
                swal("请输入诊断结果", "", "success");
                return
            }
                $.ajax({
                    url: "http://localhost:8080/com/DoctorServlet",
                    type: "post",
                    data: {
                        czf: "kaiyao",
                        id: id,
                        name: name,
                        doctorid: doctorid,
                        time: time,
                        drugid: strid,
                        drugsum: strsum,
                        drugtype: strtype,
                        bingli: $("#bingli").val()
                    },
                    dateType: "json",
                    success: function (data) {

                        swal("开药成功", "", "success");
                        setInterval(function (){
                            window.location.replace("http://localhost:8080/com/queue?doctorid=" + $("#docid").text() + "&doctorname=" + $("#docname").text() + "");
                        },1000);

                    }
                })

        })
        $("#drugno").click(function (){
            $(".yaodand").hide()
            $(".yaodan").hide()
            $(".drugdan~p").remove();
        })

        //检查
        $("#tbody").on("click","#cheneck", function (){
            $(".checkqueue,.bccheckqueue").show()
            $(".checkqueue input:eq(0)").val($(this).parent().parent().parent().children("td:eq(1)").text())
            $(".checkqueue input:eq(1)").val($(this).parent().parent().parent().children("td:eq(2)").text())
        })
        //确定检查
        $("#checkok").click(function (){

            $.ajax({
                url:"http://localhost:8080/com/DoctorServlet",//请求路径
                type:"post",//请求方式
                data:{
                    czf:"ctqueue",
                    id:$(".checkdan input:eq(0)").val()
                },//请求参数
                dataType:"json",//数据格式
                success:function (data){
                    if(data==false){

                        swal("检查单已开，通知患者去检查")


                    }else{
                        swal("请不要重复开检查单")

                    }
                }
            })
        })

        //关闭
        // $("#checkno").click(function (){
        //     $(".checkqueue,.bccheckqueue").hide()
        // })





    })




    function dispttime()
    {
        var today=new Date();
        var yearr=today.getFullYear();
        var moth=today.getMonth();
        var ri=today.getDate();
        var hh=today.getHours()
        var mm=today.getMinutes()
        var ss=today.getSeconds();
        var sh="";
        if(hh<12)
        {
            sh="AM"
        }
        else
        {
            sh="PM"
        }
        if(hh>12)
        {
            hh=hh-12
        }

        document.getElementById("myclock").value=yearr+"/"+(moth+1)+"/"+ri+"/"+hh+":"+mm+":"+ss

    }
    setInterval("dispttime()",1000)

    // function showCt(no){
    //     let ctNo=no;//获取病人编号,查询ct结果
    //     // alert(ctNo);
    //     $.ajax({
    //         url:"DoctorServlet",//请求路径
    //         type:"get",//请求方式
    //         data:{
    //             ctNo:ctNo,
    //             czf:"selCt"
    //         },//请求参数
    //         dataType:"json",//数据格式
    //         success:function (ctList){
    //             if(ctList==null){
    //                 swal("该病人没有CT记录");
    //                 $(".ct").removeClass("layui-btn-disabled");
    //                 $("#big").css({"opacity":"1"});
    //             }else {
    //                 $("#ctDiv").show();
    //                 for (let i = 0; i < ctList.length; i++) {
    //                     let tr="<tr> <td>"+ctList[i].id+"</td><td>"+ctList[i].cdiagnoseNo+"</td><td>"+ctList[i].name+"</td><td>"+ctList[i].time+"</td><td>"+ctList[i].inspectionItem+"</td><td>"+ctList[i].diagnose+"</td><td>"+ctList[i].doctorid+"</td></tr>";
    //                     // alert(tr);
    //                     $("#ctDiv tbody").append(tr);
    //
    //                 }
    //             }
    //         }
    //     })
    // }
    // function showHis(no){
    //     let ctNo=no;//获取病人编号,查询ct结果
    //     // alert(ctNo);
    //     $.ajax({
    //         url:"DoctorServlet",//请求路径
    //         type:"get",//请求方式
    //         data:{
    //             ctNo:ctNo,
    //             czf:"selDis"
    //         },//请求参数
    //         dataType:"json",//数据格式
    //         success:function (DiList){
    //             if(DiList==null){
    //                 swal("该病人没有以往病例");
    //                 $(".bl").removeClass("layui-btn-disabled");
    //                 $("#big").css({"opacity":"1"});
    //             }else {
    //                 $("#DisDiv").show();
    //                 for (let i = 0; i < DiList.length; i++) {
    //                     let tr="<tr> <td>"+DiList[i].usertype+"</td><td>"+DiList[i].time+"</td></tr>";
    //                     // alert(tr);
    //                     $("#DisDiv tbody").append(tr);
    //                 }
    //             }
    //         }
    //     })
    // }


</script>
</body>
</html>
